﻿using System;
using System.Collections.Generic;
using System.Text;

public class GarageLogic
{
    private readonly Dictionary<string, VehicleInGarage> m_VehiclesInGarage = null;

    public Dictionary<string, VehicleInGarage> VehiclesInGarage
    {
        get { return m_VehiclesInGarage; }
    }

    public GarageLogic()
    {
        m_VehiclesInGarage = new Dictionary<string, VehicleInGarage>();
    }

    public bool IsVehicleInGarage(string i_LicenseNumber, ref VehicleInGarage io_VehicleInGarage)
    {
        bool result = false;

        if (m_VehiclesInGarage.TryGetValue(i_LicenseNumber, out io_VehicleInGarage))
        {
            result = true;
        }
        
        return result;
    }

    public void EnumRangeValidator(Type i_Type, int i_ChosenEnumIndex)
    {
        if (!Enum.IsDefined(i_Type, i_ChosenEnumIndex))
        {
            Array EnumValuesArray = Enum.GetValues(i_Type);
            int MaxValue = EnumValuesArray.Length - 1;
            int MinValue = (int)EnumValuesArray.GetValue(0);
            throw new ValueOutOfRangeException("Invalid chosen option", MinValue, MaxValue);
        }
    }

    public string[] GetGarageVehicleStatusOptions()
    {
        return Enum.GetNames(typeof(VehicleInGarage.eHandleStatus));
    }

    public List<string> GetVehicleInGarageByFilter(int? i_HandleStatusFilter)
    {
        List<string> ResultList = null;

        if (i_HandleStatusFilter == null)
        {
            ResultList = new List<string>(m_VehiclesInGarage.Keys);
        }
        else
        {
            ResultList = new List<string>();

            foreach (VehicleInGarage CurrentVehicleInGarage in m_VehiclesInGarage.Values)
            {
                if (CurrentVehicleInGarage.CurrentHandleStatus.Equals((VehicleInGarage.eHandleStatus)i_HandleStatusFilter))
                {
                    ResultList.Add(CurrentVehicleInGarage.Vehicle.LicenseNumber);
                }
            }
        }

        return ResultList;
    }
}
